﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using MySql.Data.MySqlClient;

namespace DataAccess.Repository
{
    public interface IRepositoryBase<TEntity> where TEntity : class, new()
    {
        #region Write
        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="entity">要插入的记录实体</param>
        /// <returns>返回插入的记录数量</returns>
        int Insert(TEntity entity);
        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="entitys">要插入的记录实体列表</param>
        /// <returns>返回插入的记录数量</returns>
        int Insert(List<TEntity> entitys);
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity">要更新的记录实体</param>
        /// <returns>返回更新的记录数量</returns>
        int Update(TEntity entity);
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="entity">要删除的记录实体</param>
        /// <returns>返回删除的记录数量</returns>
        int Delete(TEntity entity);
        /// <summary>
        /// 按条件删除记录
        /// </summary>
        /// <param name="predicate">删除条件表达式</param>
        /// <returns>返回删除的记录数量</returns>
        int Delete(Expression<Func<TEntity, bool>> predicate);
        #endregion

        #region Read
        /// <summary>
        /// 按记录ID查找记录
        /// </summary>
        /// <param name="id">记录ID</param>
        /// <returns>返回记录实体</returns>
        TEntity FindEntity(object id);
        /// <summary>
        /// 按指定条件查找记录
        /// </summary>
        /// <param name="predicate">查找条件表达式</param>
        /// <returns>返回记录实体</returns>
        TEntity FindEntity(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// 获取记录实体集
        /// </summary>
        /// <returns>返回记录实体集</returns>
        IQueryable<TEntity> IQueryable();
        /// <summary>
        /// 按指定条件获取记录实体集
        /// </summary>
        /// <param name="predicate">条件表达式</param>
        /// <returns>返回记录实体集</returns>
        IQueryable<TEntity> IQueryable(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// 按指定SQL获取记录实体列表
        /// </summary>
        /// <param name="sql">查询记录的SQL</param>
        /// <returns>返回记录实体列表</returns>
        List<TEntity> FindList(string sql);
        /// <summary>
        /// 获取当前数据表的记录数量
        /// </summary>
        /// <param name="predicate">过滤条件</param>
        /// <returns>当前表的记录数量</returns>
        int Count(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// 获取当前数据表的记录总数量
        /// </summary>
        /// <returns>当前表的记录总数量</returns>
        int Count();

        #endregion

        #region BatchWrite

        ///// <summary>
        ///// 按指定的SQL批量插入表数据
        ///// </summary>
        ///// <param name="tableName">插入数据表名称</param>
        ///// <param name="columnNameDic">表数据列名对应字典（key=实体属性名：value=数据库表列名）</param>
        ///// <param name="columnOracleDbTypeDic">表数据列OracleDbType对应字典（key=实体属性名：value=OracleDbType）</param>
        ///// <param name="entitys">需要插入的数据实体列表</param>
        ///// <returns>返回插入的记录数量</returns>
        //int BatchInsert(string tableName, Dictionary<string, string> columnNameDic, Dictionary<string, MySqlDbType> columnOracleDbTypeDic, List<TEntity> entitys);

        ///// <summary>
        ///// 按指定的SQL批量插入表数据
        ///// </summary>
        ///// <param name="tableName">插入数据表名称</param>
        ///// <param name="columnNameDic">表数据列名对应字典（key=实体属性名：value=数据库表列名）</param>
        ///// <param name="columnOracleDbTypeDic">表数据列OracleDbType对应字典（key=实体属性名：value=OracleDbType）</param>
        ///// <param name="entitys">需要插入的数据实体列表</param>
        ///// <param name="whereColumnNameDic">过滤条件字段列名字典</param>
        ///// <returns>返回插入的记录数量</returns>
        //int BatchUpdate(string tableName, Dictionary<string, string> columnNameDic, Dictionary<string, MySqlDbType> columnOracleDbTypeDic, List<TEntity> entitys, Dictionary<string, string> whereColumnNameDic);

        #endregion
    }
}
